﻿using System.Xml.Linq;
using FarseerGames.FarseerPhysics.Mathematics;
using FreeGoo.GameEngine.Behaviors;
using FreeGoo.GameEngine.Renderables;
using FreeGoo.LevelClasses.LevelParts;

namespace FreeGoo.LevelClasses.BehaviorParts
{
    public class RotatorBehaviorPart : BehaviorPart
    {
        public override string Name { get { return "Rotator"; } }

        public override void AddBehaviorToRenderable(Level level, Renderable renderable, LevelPart levelPart, XElement element)
        {
            Rotator rotator = new Rotator(renderable);
            Vector2 center = element.Attribute("Center").ToVector2(new Vector2(0, 0));
            rotator.Center = levelPart.GetOffsetPosition(level, center);

            rotator.Speed = element.Attribute("Speed").ToFloat(0.1f);
            rotator.RotationOffset = LevelPart.ConvertDegreesToRadians(element.Attribute("RotationOffset").ToFloat(0));
        }
    }
}
